﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class CTHDBanLeDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion
        #region "Khai báo các Method"
        public bool InsertCTHDBL(CTHDBanLeDTO CTHDBanLe)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaMH", CTHDBanLe.MaMH);
            par[1] = new SqlParameter("@MaHDBL", CTHDBanLe.MaHDBL);
            par[2] = new SqlParameter("@DonGia", CTHDBanLe.DonGia);
            par[3] = new SqlParameter("@SoLuong", CTHDBanLe.SoLuong);
            par[4] = new SqlParameter("@ChietKhau", CTHDBanLe.ChietKhau);
            par[5] = new SqlParameter("@ThanhTien", CTHDBanLe.ThanhTien);
            try
            {
                helper.InsertQuery("sp_Insert_CTHDBanLe", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateCTHDBL(CTHDBanLeDTO CTHDBanLe)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaMH", CTHDBanLe.MaMH);
            par[1] = new SqlParameter("@MaHDBL", CTHDBanLe.MaHDBL);
            par[2] = new SqlParameter("@DonGia", CTHDBanLe.DonGia);
            par[3] = new SqlParameter("@SoLuong", CTHDBanLe.SoLuong);
            par[4] = new SqlParameter("@ChietKhau", CTHDBanLe.ChietKhau);
            par[5] = new SqlParameter("@ThanhTien", CTHDBanLe.ThanhTien);
            try
            {
                helper.UpdateQuery("sp_Update_CTHDBanLe", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteCTHDBL(string maMH, string maHDBL)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maMH", maMH);
            par[1] = new SqlParameter("@maHDBL", maHDBL);
            try
            {
                helper.DeleteQuery("sp_Delete_CTHDBanLe", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_CTHDBanLe()
        {
            helper = new Helper();
            DataSet ds_CTHDBL = helper.SelectQuery("sp_LayDS_CTHDBanLe");
            return ds_CTHDBL;
        }
        #endregion
    }
}